package com.lian.pet.controller;

import com.lian.pet.common.basic.response.AppResp;
import com.lian.pet.domain.dto.AddPetsDTO;
import com.lian.pet.domain.dto.QueryPetsDTO;
import com.lian.pet.domain.vo.PetsVO;
import com.lian.pet.service.PetsService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("pets")
@RestController
@AllArgsConstructor
public class PetsController {
    private final PetsService petsService;

    /**
     * 新增宠物
     * @param req
     * @param openId
     */
    @PostMapping("/add")
    public AppResp<Void> addPets(@RequestBody AddPetsDTO req, @RequestParam("openId") String openId) {
        petsService.addPets(req, openId);
        return AppResp.succeed(null);
    }

    /**
     * 查询宠物列表
     * @param req
     * @param openId
     * @return
     */
    @PostMapping("/queryList")
    public AppResp<List<PetsVO>> queryPets(@RequestBody QueryPetsDTO req, @RequestParam("openId") String openId) {
        return AppResp.succeed(petsService.queryPets(req, openId));
    }

    /**
     * 查询宠物信息
     * @param id
     * @return
     */
    @GetMapping("/getById")
    public AppResp<PetsVO> getPetsById(@RequestParam("id") Integer id) {
        return AppResp.succeed(petsService.getPets(id));
    }

    @GetMapping("/deleteById")
    public AppResp<Integer> deleteById(@RequestParam("id") Integer id) {
        petsService.deletePets(id);
        return AppResp.succeed(1);
    }

    /**
     * 修改宠物信息
     * @param id 宠物ID
     * @param req 新的宠物信息
     * @return
     */
    @PostMapping("/updateById")
    public AppResp<Void> updatePets(@RequestParam("id") Integer id, @RequestBody AddPetsDTO req) {
        petsService.updatePets(id, req);
        return AppResp.succeed(null);
    }

}
